/**
 * ClassName: DirectConfig <br/>
 * Description: <br/>
 * date: 2020/12/16 19:35<br/>
 *
 * @author lz<br />
 */
package cn.bgs.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectHdConfig {

    public static final String DIRECT_EXCHANGE_NAME = "direct.exchangehd";
    public static final String DIRECT_QUEUE_NAME = "direct.queuehd";
    public static final String DIRECT_ROUTING_KEY_NAME = "direct.routing.keyhd";

    @Bean
    DirectExchange directExchangehd(){
        //参数： 交换机名、持久化、自动删除、参数
        //return new DirectExchange(DIRECT_EXCHANGE_NAME,true,false,null);
        return new DirectExchange(DIRECT_EXCHANGE_NAME);
    }


    //配置队列
    @Bean
    Queue directQueuehd() {

        //参数： 队列名、持久化、是否独占、自动删除、参数
        //return new Queue(DIRECT_QUEUE_NAME,true,false,false,null);
        return new Queue(DIRECT_QUEUE_NAME);
    }

    //绑定队列到交换机
    @Bean
    Binding directBindinghd() {
        //参数：队列名、目的类型(使用默认)、交换机名、路右键名、参数
        //return new Binding(DIRECT_QUEUE_NAME, Binding.DestinationType.QUEUE, DIRECT_EXCHANGE_NAME,DIRECT_ROUTING_KEY_NAME,null);
        return BindingBuilder.bind(directQueuehd()).to(directExchangehd()).with(DIRECT_ROUTING_KEY_NAME);
    }

}
